package com.wao.cms.service;

import com.wao.cms.domain.PropertyValue;
import com.wao.cms.repository.PropertyValueRepository;
import com.wao.cms.service.dto.PropertyValueDTO;
import com.wao.cms.service.mapper.PropertyValueMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Service Implementation for managing PropertyValue.
 */
@Service
@Transactional
public class PropertyValueService {

    private final Logger log = LoggerFactory.getLogger(PropertyValueService.class);

    private final PropertyValueRepository propertyValueRepository;

    private final PropertyValueMapper propertyValueMapper;

    public PropertyValueService(PropertyValueRepository propertyValueRepository, PropertyValueMapper propertyValueMapper) {
        this.propertyValueRepository = propertyValueRepository;
        this.propertyValueMapper = propertyValueMapper;
    }

    /**
     * Save a propertyValue.
     *
     * @param propertyValueDTO the entity to save
     * @return the persisted entity
     */
    public PropertyValueDTO save(PropertyValueDTO propertyValueDTO) {
        log.debug("Request to save PropertyValue : {}", propertyValueDTO);
        PropertyValue propertyValue = propertyValueMapper.toEntity(propertyValueDTO);
        propertyValue = propertyValueRepository.save(propertyValue);
        return propertyValueMapper.toDto(propertyValue);
    }

    /**
     *  Get all the propertyValues.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true)
    public Page<PropertyValueDTO> findAll(Pageable pageable) {
        log.debug("Request to get all PropertyValues");
        return propertyValueRepository.findAll(pageable)
            .map(propertyValueMapper::toDto);
    }

    /**
     *  Get one propertyValue by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true)
    public PropertyValueDTO findOne(Long id) {
        log.debug("Request to get PropertyValue : {}", id);
        PropertyValue propertyValue = propertyValueRepository.findOne(id);
        return propertyValueMapper.toDto(propertyValue);
    }

    /**
     *  Delete the  propertyValue by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete PropertyValue : {}", id);
        propertyValueRepository.delete(id);
    }

    /**
     *  Get one propertyValue by id.
     *
     *  @param pageId the id of the page
     *  @return the entity
     */
    @Transactional(readOnly = true)
    public List<PropertyValueDTO> findByPageId(Long pageId) {
        log.debug("Request to get PropertyValues by Page : {}", pageId);
        List<PropertyValue> propertyValues = propertyValueRepository.findByPageId(pageId);
        return propertyValueMapper.toDto(propertyValues);
    }
}
